package com.dkd.flow.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.enums.BusinessType;
import com.dkd.flow.domain.EProcessDefinition;
import com.dkd.flow.service.IEProcessDefinitionService;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.common.core.page.TableDataInfo;

/**
 * 流程定义Controller
 *
 * @author itheima
 * @date 2025-01-26
 */
@Api(tags = "流程定义Controller")
@RestController
@RequestMapping("/flow/definition")
public class EProcessDefinitionController extends BaseController
{
    @Autowired
    private IEProcessDefinitionService eProcessDefinitionService;

    /**
     * 查询流程定义列表
     */
    @ApiOperation("查询流程定义列表")
    @PreAuthorize("@ss.hasPermi('flow:definition:list')")
    @GetMapping("/list")
    public TableDataInfo list(EProcessDefinition eProcessDefinition)
    {
        startPage();
        List<EProcessDefinition> list = eProcessDefinitionService.selectEProcessDefinitionList(eProcessDefinition);
        return getDataTable(list);
    }

    /**
     * 导出流程定义列表
     */
    @ApiOperation("导出流程定义列表")
    @PreAuthorize("@ss.hasPermi('flow:definition:export')")
    @Log(title = "流程定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EProcessDefinition eProcessDefinition)
    {
        List<EProcessDefinition> list = eProcessDefinitionService.selectEProcessDefinitionList(eProcessDefinition);
        ExcelUtil<EProcessDefinition> util = new ExcelUtil<EProcessDefinition>(EProcessDefinition.class);
        util.exportExcel(response, list, "流程定义数据");
    }

    /**
     * 获取流程定义详细信息
     */
    @ApiOperation("获取流程定义详细信息")
    /*@PreAuthorize("@ss.hasPermi('flow:definition:query')")*/
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID)
    {
        return success(eProcessDefinitionService.selectEProcessDefinitionByID(ID));
    }

    /**
     * 新增流程定义
     */
    @ApiOperation("新增流程定义")
    @PreAuthorize("@ss.hasPermi('flow:definition:add')")
    @Log(title = "流程定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EProcessDefinition eProcessDefinition)
    {
        return toAjax(eProcessDefinitionService.insertEProcessDefinition(eProcessDefinition));
    }

    /**
     * 修改流程定义
     */
    @ApiOperation("修改流程定义")
    @PreAuthorize("@ss.hasPermi('flow:definition:edit')")
    @Log(title = "流程定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EProcessDefinition eProcessDefinition)
    {
        return toAjax(eProcessDefinitionService.updateEProcessDefinition(eProcessDefinition));
    }

    /**
     * 删除流程定义
     */
    @ApiOperation("删除改流程定义")
    @PreAuthorize("@ss.hasPermi('flow:definition:remove')")
    @Log(title = "流程定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs)
    {
        return toAjax(eProcessDefinitionService.deleteEProcessDefinitionByIDs(IDs));
    }
}
